home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacPerl 5.0.3 / Preinstalled MacPerl (FAT) / lib / auto / DynaLoader / dl_findfile.al < prev   
Encoding:
Text File  |  1995-07-29  |  2.5 KB  |  70 lines  |  [TEXT/McPL]

  1. # NOTE: Derived from :::lib:DynaLoader.pm.  Changes made here will be lost.
  2. package DynaLoader;
  3.  
  4. sub dl_findfile {
  5.     # Read ext/DynaLoader/DynaLoader.doc for detailed information.
  6.     # This function does not automatically consider the architecture
  7.     # or the perl library auto directories.
  8.     my (@args) = @_;
  9.     my (@dirs,  $dir);   # which directories to search
  10.     my (@found);         # full paths to real files we have found
  11.     my ($vms) = ($Config{'osname'} eq 'VMS');
  12.  
  13.     print STDERR "dl_findfile(@args)\n" if $dl_debug;
  14.  
  15.     # accumulate directories but process files as they appear
  16.     arg: foreach(@args) {
  17.         #  Special fast case: full filepath requires no search
  18.         if (/.:/ && -f $_ && !$do_expand){
  19.         push(@found,$_);
  20.         last arg unless wantarray;
  21.         next;
  22.     }
  23.  
  24.         # Deal with directories first:
  25.         #  Using a -L prefix is the preferred option (faster and more robust)
  26.         if (m:^-L:){ s/^-L//; push(@dirs, $_); next; }
  27.         #  Otherwise we try to try to spot directories by a heuristic
  28.         #  (this is a more complicated issue than it first appears)
  29.         if (m/.:/ && -d $_){   push(@dirs, $_); next; }
  30.  
  31.         #  Only files should get this far...
  32.         my(@names, $name);    # what filenames to look for
  33.         if (m:-l: ){          # convert -lname to appropriate library name
  34.             s/-l//;
  35.             push(@names,"lib$_.$dl_so");
  36.             push(@names,"lib$_.a");
  37.         }else{                # Umm, a bare name. Try various alternatives:
  38.             # these should be ordered with the most likely first
  39.             push(@names,"$_.$dl_so")     unless m/\.$dl_so$/o;
  40.             push(@names,"lib$_.$dl_so")  unless m/.:/;
  41.             push(@names,"$_.o")          unless m/\.(o|$dl_so)$/o;
  42.             push(@names,"$_.a")          unless m/\.a$/;
  43.             push(@names, $_);
  44.         }
  45.         foreach $dir (@dirs, @dl_library_path) {
  46.             next unless -d $dir;
  47.             foreach $name (@names) {
  48.         my($file) = "$dir:$name";
  49.                 print STDERR " checking in $dir for $name\n" if $dl_debug;
  50.         $file = _check_file($file);
  51.         if ($file){
  52.                     push(@found, $file);
  53.                     next arg; # no need to look any further
  54.                 }
  55.             }
  56.         }
  57.     }
  58.     if ($dl_debug) {
  59.         foreach(@dirs) {
  60.             print STDERR " dl_findfile ignored non-existent directory: $_\n" unless -d $_;
  61.         }
  62.         print STDERR "dl_findfile found: @found\n";
  63.     }
  64.     return $found[0] unless wantarray;
  65.     @found;
  66. }
  67.  
  68.  
  69. 1;
  70.